#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "sst_id.h"
#include "mem.h"
#include "entry.h"

namespace VirtualR {
class SSTable {
 public:
  SSTable(SkipList *mem, SSTableID id);
  SSTable(SSTableID &id);
  SSTable(std::vector<Entry_t> &entries, uint64_t &pos, SSTableID &id);
  int32_t remove_file();
  // get min value in this sst
  std::string lower();
  // get max value in this sst
  std::string higher();
  std::vector<Entry_t> load();
  uint64_t no();
  std::pair<bool, std::string> search(std::string key);
  uint64_t disk_size();
  uint64_t get_count() {
    return total_count_;
  }

 private:
  void dump_to_disk(std::string &sst_content);
  std::string get_value(uint32_t pos);

  SSTableID id_;
  // key
  std::vector<std::string> keys_;
  // value的偏移
  std::vector<uint64_t> offsets_;
  // 存value的地方
  std::string values_;
  uint64_t total_count_{0};
  // meta部分大小
  uint64_t meta_size_{0};
};

} // namespace VirtualR